<?php
class cls_control_productdetail extends cls_control_base
{
	function __construct()
	{
		$this->user_name= $_SESSION['user']['ID'];
		$this->product_id= $_REQUEST['product_id'];
		
	}
	
	function show_detail_page()
	{
		$product_serve=cls_serve_base::get_instance($this->name);
		$product_info=$product_serve->get_product_info($this->product_id);
		$detail_page=array("Name"=>$this->get_product_name(),
				"Author"=>$this->get_product_author(),
				"Price"=>sprintf("%.2f",$this->get_product_original_price()),
				"Discount_Type"=>$this->get_product_discount_type(),
				"Discount_Amount"=>$this->get_product_discount_amount(),
				"Current_Price"=>sprintf("%.2f",$this->get_current_price()),
				"Saved_Value"=>sprintf("%.2f",$product_serve->get_saved_value($this->product_id)),
				"Saved_Proportion"=>sprintf("%.1f",$product_serve->get_saved_proportion($this->product_id)),
				"Image"=>$this->get_product_image(),
				"Stock"=>$this->get_product_stock(),
				"favorites"=>$this->get_favorites(),
				"description"=>$this->get_description(),
				"comment"=>$this->get_comment(),
				"isbn"=>$product_info["ISBN"],
				"language"=>$product_info["ProductLanguage"],
				"publisher"=>$product_info["Publisher"],
				"totalpage"=>$product_info["TotalPage"],
				"quantity"=>$this->get_product_quantity()				
				);

		echo json_encode($detail_page);
	
	}
	
	function get_()
	{
		$product_serve=cls_serve_base::get_instance($this->name);
		$product_serve->product_info($this->user_name,$this->product_id);
	}
	
	function set_favorites()
	{
		$product_serve=cls_serve_base::get_instance($this->name);
		if(!empty($_SESSION['user']))
		{
			$product_serve->set_favorites($this->user_name,$this->product_id);
			echo 1;
		}
		else
		{	
			echo 0;
		}

	}
	
	function get_current_price_json()
	{
		$product_serve=cls_serve_base::get_instance($this->name);
		$current_price=$product_serve->get_current_price($this->product_id);
		echo json_encode($current_price);
	}
		
	function get_current_price()
	{
		$product_serve=cls_serve_base::get_instance($this->name);
		$current_price=$product_serve->get_current_price($this->product_id);
		return $current_price;
	}
	
	function get_product_original_price()
	{
		$product_serve=cls_serve_base::get_instance($this->name);
		$product_original_price=$product_serve->get_product_original_price($this->product_id);
		return $product_original_price;
	}
	
	function get_product_discount_type()
	{
		$product_serve=cls_serve_base::get_instance($this->name);
		$product_discount=$product_serve->get_product_discount($this->product_id);
		return $product_discount['Type'];
	}
	
	function get_product_discount_amount()
	{
		$product_serve=cls_serve_base::get_instance($this->name);
		$product_discount=$product_serve->get_product_discount($this->product_id);
		return $product_discount['Amount'];
	}
	
	function get_product_current_price()
	{
		$product_serve=cls_serve_base::get_instance($this->name);
		$product_current_price=$product_serve->get_product_current_price($this->product_id);
		return $product_current_price;
	}
	
	function get_product_name()
	{
		$product_serve=cls_serve_base::get_instance($this->name);
		$product_name=$product_serve->get_product_name($this->product_id);
		return $product_name;
	}
	
	function get_product_description()
	{
		$product_serve=cls_serve_base::get_instance($this->name);
		$product_description=$product_serve->get_product_description($this->product_id);
		return $product_description;
	}

	function get_product_image()
	{
		$product_serve=cls_serve_base::get_instance($this->name);
		$product_image=$product_serve->get_product_image($this->product_id);
		return $product_image;
	}
	
	function get_product_publisher()
	{
		$product_serve=cls_serve_base::get_instance($this->name);
		$product_publisher=$product_serve->get_product_publisher($this->product_id);
		return $product_publisher;
	}
	
	function get_product_language()
	{
		$product_serve=cls_serve_base::get_instance($this->name);
		$product_language=$product_serve->get_product_language($this->product_id);
		return $product_language;
	}
	
	function get_product_author()
	{
		$product_serve=cls_serve_base::get_instance($this->name);
		$product_author=$product_serve->get_product_author($this->product_id);
		return $product_author;
	}
	
	function get_product_quantity()
	{
		$product_serve=cls_serve_base::get_instance($this->name);
		$product_quantity=$product_serve->get_product_quantity($this->product_id);
		return $product_quantity;
	}
	
	function get_product_totalpage()
	{
		$product_serve=cls_serve_base::get_instance($this->name);
		$product_totalpage=$product_serve->get_product_totalpage($this->product_id);
		return $product_totalpage;
	}
	
	function get_product_stock()
	{
		$product_serve=cls_serve_base::get_instance($this->name);
		$product_stock=$product_serve->get_product_stock($this->product_id);
	    return $product_stock;
	}
	
	function get_favorites()
	{
		$product_serve=cls_serve_base::get_instance($this->name);
		$favorites=$product_serve->get_favorites($this->user_name,$this->product_id);
		return $favorites;		
	}
	
	function get_comment()
	{
		$product_serve=cls_serve_base::get_instance($this->name);
		$product_comment=$product_serve->get_comment($this->product_id);
		return $product_comment;
	}
	
	function get_description()
	{
		$product_serve=cls_serve_base::get_instance($this->name);
		$product_description=$product_serve->get_description($this->product_id);
		return $product_description;
	}
	
	function set_user()
	{
		$_SESSION['user']='1';
	}

}